package model;

import java.util.ArrayList;
import java.util.List;

import dao.CourseDAO;

/**
 * 
 * @author 蔡锦涛
 *
 */
public class Course implements CourseDAO {
	private String name;
        private String teacher;
        private int numberSelected;
      /**
           * 课程限制人数
       */
	private int numberOfStudents;
	private ArrayList<Student> students = new ArrayList<>();
	
	public Course(String name,String teacher,int numSelected,int numberOfStudents,Student stu){
                this.name=name;
                this.teacher=teacher;
                this.numberSelected = numSelected;
                this.numberOfStudents = numberOfStudents;
                this.students.add(stu);
                
        }
        public String getTeacher() {
            return teacher;
        }

        public void setTeacher(String teacher) {
            this.teacher = teacher;
        }

        public void setNumberSelected(int numberSelected) {
            this.numberSelected = numberSelected;
        }

        public int getNumberSelected() {
            return numberSelected;
        }
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getNumberOfStudents() {
		return numberOfStudents;
	}

	public void setNumberOfStudents(int numberOfStudents) {
		this.numberOfStudents = numberOfStudents;
	}

	public ArrayList<Student> getStudents() {
		return students;
	}

	public void setStudents(ArrayList<Student> students) {
		this.students = students;
	}

	
	public boolean add(Student s) { //���ѧ��
		if(students.size() < numberOfStudents) {
			for (int i = 0; i < students.size(); i++) {
				if(students.get(i).equals(s)) {
					return false;
				}
			}
			students.add(s);
			return true;
		}
		return false;
	}
	
	public boolean delete(Student s) { //ɾ��ѧ��
		if(students.isEmpty()) {
			return false;
		}
		for (int i = 0; i < students.size(); i++) {
			if(students.get(i).equals(s)) {
				students.remove(i);
				return true;
			}
		}
		return false;
		
	}
	
	
}
